package com.sino.second.business.service;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import com.sino.model.ExpertModel;
import com.sino.second.bean.TblXmfs3;
import com.sino.second.bean.TblXmjg2;
import com.sino.second.bean.TblXmjg3;
import com.sino.second.bean.TblZjpsfp;
import com.sino.second.business.IExpertsVoteService;
import com.sino.second.dao.IExpertsVoteDAO;
import com.sino.second.dao.IZjpsfpDAO;
import com.sino.second.dao.hibernate.BaseDataDAO;
import com.sino.second.model.ExpertsReviewModel3;
import com.sino.second.model.VoteModel;
import com.sino.second.model.XmReviewResults2;
import com.sino.second.model.XmReviewResults3;
import com.sino.second.util.BeanAndModelConverter;
import com.sino.util.SysParameter;

public class ExpertsVoteServiceImpl implements IExpertsVoteService {
	private IExpertsVoteDAO expertsVoteDAO;// 引入IExpertsVoteDAO

	private IZjpsfpDAO zjpsfpDAO;// 引入zjpsfpDAO

	private BaseDataDAO baseDataDAO;// 引入BaseDataDAO

	/**
	 * @param expertsVoteDAO
	 *            the expertsVoteDAO to set
	 */
	public void setExpertsVoteDAO(IExpertsVoteDAO expertsVoteDAO) {
		this.expertsVoteDAO = expertsVoteDAO;
	}

	/**
	 * @param zjpsfpDAO
	 *            the zjpsfpDAO to set
	 */
	public void setZjpsfpDAO(IZjpsfpDAO zjpsfpDAO) {
		this.zjpsfpDAO = zjpsfpDAO;
	}

	/**
	 * @param baseDataDAO
	 *            the baseDataDAO to set
	 */
	public void setBaseDataDAO(BaseDataDAO baseDataDAO) {
		this.baseDataDAO = baseDataDAO;
	}

	/**
	 * 查询复审结果表，列出所有通过复审的项目信息
	 */
	public List<XmReviewResults2> listAllPastSecondReviewProject(String hqlWhere) {
		List<TblXmjg2> TblXmjg2List = this.expertsVoteDAO
				.listAllPastSecondReviewProject(hqlWhere);// 调用expertsVoteDAO的方法查询列出所有通过复审的项目信息
		/**
		 * 以下代码将beanList转化为modelList，即TblXmjg2List转化为XmReviewResults2List
		 */
		List<XmReviewResults2> XmReviewResults2List = new ArrayList<XmReviewResults2>();
		if (null != TblXmjg2List && TblXmjg2List.size() > 0) {
			for (TblXmjg2 xmjg2 : TblXmjg2List) {
				XmReviewResults2 xmReviewResults2 = BeanAndModelConverter
						.getXmReviewResults2ByTblXmjg2(xmjg2);
				XmReviewResults2List.add(xmReviewResults2);
			}
		}
		return XmReviewResults2List;
	}

	/**
	 * 查询大评委分数表，通过专家id查询列出所有符合的项目投票信息
	 */
	public List<ExpertsReviewModel3> listThirdReviewProjectByExpert(
			String expertId, String hqlWhere) {
		List<TblXmfs3> xmfs3List = this.expertsVoteDAO.listTblXmfs3ByExpert(
				new Integer(expertId), hqlWhere);// 调用expertsVoteDAO的方法，通过专家id查询大评委分数表，列出所有符合条件的项目投票信息
		/**
		 * 以下代码将beanList转化为modelList,即将xmfs3List转化为expertsReviewModel3List
		 */
		List<ExpertsReviewModel3> expertsReviewModel3List = new ArrayList<ExpertsReviewModel3>();
		for (TblXmfs3 xmfs3 : xmfs3List) {
			ExpertsReviewModel3 expertsReviewModel3 = BeanAndModelConverter
					.getExpertsReviewModel3ByTblXmfs3(xmfs3);
			expertsReviewModel3List.add(expertsReviewModel3);
		}
		return expertsReviewModel3List;
	}

	/**
	 * 查询专家分配表，根据评审组id取得符合条件的专家信息
	 */
	public List<ExpertModel> listReviewExpertByXmpsmc(String xmpsmcId,
			String hqlWhere) {
		List<TblZjpsfp> zjpsfpList = this.zjpsfpDAO.listZjpsfpByXmpsmcId(
				xmpsmcId, hqlWhere);// 调用zjpsfpDAO的方法，通过xmpsmcId查询符合条件的专家信息
		hqlWhere=hqlWhere.replace("tzpf", "xmfs3");
		List<Integer> expertIdList=this.expertsVoteDAO.listXmfs3Expert(hqlWhere);
		
		/**
		 * 以下代码将beanList转化为modelList，即将zjpsfpList转化为emList
		 */
		List<ExpertModel> emList = new ArrayList<ExpertModel>();
		for (TblZjpsfp tzpf : zjpsfpList) {
			ExpertModel em = BeanAndModelConverter.getExpertModel(tzpf
					.getTblZhuanjiarukuxinxibiao());
			if(this.isExitInArray(em.getFBh(), expertIdList))
			{
				em.setAlreadyThirdReview(true);
			}
			emList.add(em);
		}
		return emList;
	}

	/**
	 * 保存或者更新大评委分数表中的一条项目投票信息
	 */
	public void saveOrUpdateExpertsReviewModel3(
			ExpertsReviewModel3 expertsReviewModel3, String jydjId,
			String pxdjId, String hqlWhere) {
		TblXmfs3 xmfs3 = BeanAndModelConverter
				.getTblXmfs3ByExpertsReviewModel3(expertsReviewModel3);// 将大评委分数表model转化为大评委分数表bean
		if (null != jydjId && !"".equals(jydjId)) {// 判断建议等级是否为空
			xmfs3.setJydj(this.baseDataDAO.findXmpsdj(jydjId));// 将建议等级bean存入大评委分数bean
		}
		if (null != pxdjId && !"".equals(pxdjId)) {// 判断评选等级是否为空
			xmfs3.setPxdj(this.baseDataDAO.findXmpsdj(pxdjId));// 将评选等级bean存入大评委分数bean
		}
		TblXmfs3 tblXmfs3 = this.expertsVoteDAO
				.findTblXmfs3ByBasicInfoAndExpert(xmfs3.getBasicinfo()
						.getZlid(), xmfs3.getTblZhuanjiarukuxinxibiao()
						.getFBh(), hqlWhere);// 调用expertsVoteDAO的方法，通过项目idyu专家id查找大评委分数表中的唯一一条数据
		if (null == tblXmfs3) {// 如果没有查出符合条件的数据
			this.expertsVoteDAO.saveTblXmfs3(xmfs3);// 则将新对象存入大评委分数表
		} else {// 否则，将数据转存入此对象
			tblXmfs3.setJydj(xmfs3.getJydj());
			tblXmfs3.setPxdj(xmfs3.getPxdj());
			tblXmfs3.setPsrq(xmfs3.getPsrq());
			tblXmfs3.setBasicinfo(xmfs3.getBasicinfo());
			tblXmfs3.setTblZhuanjiarukuxinxibiao(xmfs3
					.getTblZhuanjiarukuxinxibiao());
			tblXmfs3.setYear(xmfs3.getYear());
			this.expertsVoteDAO.updateTblXmfs3(tblXmfs3);// 调用expertsVoteDAO的方法，更新该条数据
		}

	}

	/**
	 * 查询列出大评委分数表中的数据，并构造存入List<VoteModel>
	 */
	public List<VoteModel> listTblXmfs3VoteResult(String hqlWhere) {
		List voteResultList = this.expertsVoteDAO
				.listTblXmfs3VoteResult(hqlWhere);// 调用expertsVoteDAO的方法获取大评委分数表中的计算数据
		String hqlWhere1 = hqlWhere.replaceAll("xmfs3", "xmjg3");
		List<TblXmjg3> xmjgList = this.expertsVoteDAO
				.listAllTblXmjg3(hqlWhere1);// 获得大评委结果表中的数据
		List<String> xmIdList = new ArrayList<String>();// 新建一个项目id列表
		for (TblXmjg3 xmjg : xmjgList) {
			xmIdList.add(xmjg.getBasicinfo().getZlid());// 将项目id循环存入项目id列表
		}
		hqlWhere = hqlWhere.replaceAll("xmfs3", "tx3");
		Iterator it = voteResultList.iterator();// 获得遍历器
		List<VoteModel> voteModelList = new ArrayList<VoteModel>();
		double alreadyVoteExpertCount = this
				.listAlreadyVoteExpertCount(hqlWhere);// 获得已经投票的票数
		while (it.hasNext()) {
			VoteModel vm = new VoteModel();// 声明一个VoteModel
			Object[] al = (Object[]) it.next();// 将it.next()强制转换为Object[]
			vm.setBasicInfoId(al[0].toString());// 存入项目id
			vm.setBasicInfoName(al[1].toString());// 存入项目名称
			vm.setXk(al[2].toString());// 存入学科
			vm.setJydjId(al[3].toString());// 存入建议等级id
			vm.setJydjName(al[4].toString());// 存入建议等级名称
			vm.setOutstandingWinnerCount(al[5].toString());// 存入特等奖票数
			vm.setFirstPrizeCount(al[6].toString());// 存入一等奖票数
			vm.setSecondPrizeCount(al[7].toString());// 存入二等奖票数
			vm.setThirdPrizeCount(al[8].toString());// 存入三等奖票数
			vm.setAbstentionCount(al[9].toString());// 存入弃权票数
			if (new Double(vm.getOutstandingWinnerCount())
					/ alreadyVoteExpertCount >= 4.0 / 5.0)// 如果特等奖票数/已评票数>0.8
			{
				vm.setFinalPrizeId(SysParameter.outstandingWinner);// 设定最终奖项为特等奖
				vm.setFinalPrize("特等奖");
				vm.setFinalPrizeCount(vm.getOutstandingWinnerCount());// 设定最终奖项票数为特等奖票数
			} else if ((new Double(vm.getOutstandingWinnerCount()) + new Double(
					vm.getFirstPrizeCount()))
					/ alreadyVoteExpertCount >= 2.0 / 3.0)// 如果没有评上特等奖，则判断特等奖票数加上一等奖票数/已评票数>0.66666..
			{
				vm.setFinalPrizeId(SysParameter.firstPrize);// 设定最终奖项为一等奖
				vm.setFinalPrize("一等奖");
				vm.setFinalPrizeCount(new Integer(new Integer(vm
						.getOutstandingWinnerCount())
						+ new Integer(vm.getFirstPrizeCount())).toString());// 设定最终奖项票数为特等奖票数加上一等奖票数
			} else if ((new Double(vm.getOutstandingWinnerCount())
					+ new Double(vm.getFirstPrizeCount()) + new Double(vm
					.getSecondPrizeCount()))
					/ alreadyVoteExpertCount >= 1.0 / 2.0)// 如果没有评上特等奖以及一等奖，则判断特等奖票数加上一等奖票数加上二等奖票数/已评票数>0.5
			{
				vm.setFinalPrizeId(SysParameter.secondPrize);// 设定最终奖项为二等奖
				vm.setFinalPrize("二等奖");
				vm.setFinalPrizeCount(new Integer(new Integer(vm
						.getOutstandingWinnerCount())
						+ new Integer(vm.getFirstPrizeCount())
						+ new Integer(vm.getSecondPrizeCount())).toString());// 设定最终奖项票数为特等奖票数加上一等奖票数加上二等奖票数
			} else// 否则
			{
				vm.setFinalPrizeId(SysParameter.thirdPrize);// 设定最终奖项为三等奖
				vm.setFinalPrize("三等奖");
				vm.setFinalPrizeCount(new Integer(new Integer(vm
						.getOutstandingWinnerCount())
						+ new Integer(vm.getFirstPrizeCount())
						+ new Integer(vm.getSecondPrizeCount())
						+ new Integer(vm.getThirdPrizeCount())).toString());// 设定最终奖项票数为特等奖票数加上一等奖票数加上二等奖票数加上三等奖票数
			}
			if (this.isExitInArray(vm.getBasicInfoId(), xmIdList)) {
				vm.setPassThirdCheck(true);
			}
			voteModelList.add(vm);
		}
		return voteModelList;
	}

	/**
	 * 将listTblXmfs3VoteResult()返回的结果按照最终奖项进行排序返回
	 */
	public List<VoteModel> listTblXmfs3VoteResultSort(String hqlWhere) {
		List<VoteModel> voteModelList = this.listTblXmfs3VoteResult(hqlWhere);
		List<VoteModel> voteModelTempSortList=new ArrayList<VoteModel>();
		List<VoteModel> voteModelSortList = new ArrayList<VoteModel>();
		/**
		 * 每个奖项循环一次，依次往voteModelSortList中插入特等奖、一等奖、二等奖、三等奖、其余奖项，根据list的先进先出原则，展示的时候排序顺序为特等奖、一等奖、二等奖、三等奖、其余奖项
		 */
		for (VoteModel vm : voteModelList) {
			if (vm.getFinalPrize().equals("特等奖")) {
				voteModelTempSortList.add(vm);
			}
		}
		voteModelSortList.addAll(this.sortList(voteModelTempSortList));
		voteModelTempSortList=new ArrayList<VoteModel>();
		
		for (VoteModel vm : voteModelList) {
			if (vm.getFinalPrize().equals("一等奖")) {
				voteModelTempSortList.add(vm);
			}
		}
		
		voteModelSortList.addAll(this.sortList(voteModelTempSortList));
		voteModelTempSortList=new ArrayList<VoteModel>();
		
		for (VoteModel vm : voteModelList) {
			if (vm.getFinalPrize().equals("二等奖")) {
				voteModelTempSortList.add(vm);
			}
		}
		
		voteModelSortList.addAll(this.sortList(voteModelTempSortList));
		voteModelTempSortList=new ArrayList<VoteModel>();
		
		for (VoteModel vm : voteModelList) {
			if (vm.getFinalPrize().equals("三等奖")) {
				voteModelTempSortList.add(vm);
			}
		}
		
		voteModelSortList.addAll(this.sortList(voteModelTempSortList));
		voteModelTempSortList=new ArrayList<VoteModel>();
		
		for (VoteModel vm : voteModelList) {
			if (!vm.getFinalPrize().equals("特等奖")
					&& !vm.getFinalPrize().equals("一等奖")
					&& !vm.getFinalPrize().equals("二等奖")
					&& !vm.getFinalPrize().equals("三等奖")) {
				voteModelTempSortList.add(vm);
			}
		}
		if(null!=voteModelTempSortList&&voteModelTempSortList.size()>0)
		{
			voteModelSortList.addAll(this.sortList(voteModelTempSortList));
		}
		return voteModelSortList;
	}

	/**
	 * 调用zjpsfpDAO的方法根据xmpsmcId查询专家分配表，查询已经分配给相应xmpsmcId的专家数量
	 */
	public int listAssignExpertCountByXmpsmc(String xmpsmcId, String hqlWhere) {
		return this.zjpsfpDAO.listAssignExpertCountByXmpsmcId(xmpsmcId,
				hqlWhere);
	}

	/**
	 * 查询大评委分数表，查询列出已经投票的专家数
	 */
	public int listAlreadyVoteExpertCount(String hqlWhere) {
		return this.expertsVoteDAO.listAlreadyVoteExpertCount(hqlWhere);
	}

	/**
	 * 保存或者更新大评委结果表中的一条项目投票结果信息
	 */

	public void saveOrUpdateXmReviewResults3(XmReviewResults3 xmReviewResults3,
			String jydjId, String pxdjId, String hqlWhere) {
		TblXmjg3 xmjg3 = BeanAndModelConverter
				.getTblXmjg3ByXmReviewResults3(xmReviewResults3);// 将大评委结果表model转化大评委结果表bean，即将xmReviewResults3转化为xmjg3
		if (null != jydjId && !"".equals(jydjId)) {// 如果建议等级不为空
			xmjg3.setJydj(this.baseDataDAO.findXmpsdj(jydjId));// 存入建议等级
		}
		if (null != pxdjId && !"".equals(pxdjId)) {// 如果评审等级不为空
			xmjg3.setPxjj(this.baseDataDAO.findXmpsdj(pxdjId));// 存入评审等级
		}

		TblXmjg3 tblXmjg3 = this.expertsVoteDAO.findTblXmjg3ByBasicInfoId(xmjg3
				.getBasicinfo().getZlid(), hqlWhere);// 根据项目id查找大评委结果表中的唯一一条记录，并赋予一个对象
		if (null == tblXmjg3) {// 判断该对象是否为空
			this.expertsVoteDAO.saveTblXmjg3(xmjg3);// 如果为空则保存一个新对象
		} else {// 否则
			tblXmjg3.setBasicinfo(xmjg3.getBasicinfo());
			tblXmjg3.setJydj(xmjg3.getJydj());
			tblXmjg3.setPs(xmjg3.getPs());
			tblXmjg3.setPsrq(xmjg3.getPsrq());
			tblXmjg3.setPxjj(xmjg3.getPxjj());
			tblXmjg3.setUsername(xmjg3.getUsername());
			tblXmjg3.setYear(xmjg3.getYear());
			this.expertsVoteDAO.updateTblXmjg3(tblXmjg3);// 将数据转存入现有对象，更新数据库记录
		}

	}

	/**
	 * 查询大评委结果表，查询列出所有记录
	 */
	public List<XmReviewResults3> listAllXmReviewResults3(String hqlWhere) {
		List<TblXmjg3> xmjg3List = this.expertsVoteDAO
				.listAllTblXmjg3(hqlWhere);// 调用expertsVoteDAO的方法查询列出大评委结果表中的所有数据
		/**
		 * 一下代码将beanList转化为modelList,即将xmjg3List转化为xmReviewResults3List
		 */
		List<XmReviewResults3> xmReviewResults3List = new ArrayList<XmReviewResults3>();
		for (TblXmjg3 xmjg3 : xmjg3List) {
			XmReviewResults3 xmReviewResults3 = BeanAndModelConverter
					.getXmReviewResults3ByTblXmjg3(xmjg3);
			xmReviewResults3List.add(xmReviewResults3);
		}
		return xmReviewResults3List;
	}

	public void delTblXmjg3(String hqlWhere) {
		this.expertsVoteDAO.delTblXmjg3(hqlWhere);

	}

	public File exportVoteResult(String fileName,
			List<XmReviewResults3> xmReviewResults3List) {
		File exportFile = null;
		if (!"".equals(fileName) && fileName.length() > 0) {
			try {
				exportFile = new File(fileName);
				if (!exportFile.exists()) {
					exportFile.createNewFile();
				}
				FileOutputStream os = new FileOutputStream(exportFile);
				WritableWorkbook book = null;
				book = Workbook.createWorkbook(os);
				WritableSheet sheet1 = book.createSheet("评审选票", 0);// 设置第一个sheet的名称
				sheet1.getSettings().setTopMargin(1.0);// 设置页面顶边距,此长度与excel实际长度的转化公式：1：2.5
				sheet1.getSettings().setBottomMargin(1.0);// 设置页面底边距,此长度与excel实际长度的转化公式：1：2.5
				sheet1.getSettings().setLeftMargin(0.2);// 设置页面左边距,此长度与excel实际长度的转化公式：1：2.5
				sheet1.getSettings().setRightMargin(0.2);// 设置页面右边距,此长度与excel实际长度的转化公式：1：2.5
				/**
				 * 设置普通单元格样式
				 */
				WritableFont wf = new WritableFont(WritableFont.ARIAL, 12,
						WritableFont.NO_BOLD, false,
						UnderlineStyle.NO_UNDERLINE, Colour.BLACK);

				WritableCellFormat wcf = new WritableCellFormat(wf);
				wcf.setBackground(Colour.WHITE);// 设置背景色
				wcf.setAlignment(Alignment.CENTRE);// 设置水平对齐方式
				wcf.setVerticalAlignment(VerticalAlignment.CENTRE);// 设置垂直对齐方式
				wcf.setBorder(Border.ALL, BorderLineStyle.THIN);// 设置单元格边框样式
				wcf.setWrap(true);// 设置自动换行

				/**
				 * 设置表头样式
				 */
				WritableFont wfTitle = new WritableFont(WritableFont.ARIAL, 24,
						WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
						Colour.BLACK);

				WritableCellFormat wcfTitle = new WritableCellFormat(wfTitle);
				wcfTitle.setBackground(Colour.WHITE);// 设置背景色
				wcfTitle.setAlignment(Alignment.CENTRE);// 设置水平对齐方式
				wcf.setVerticalAlignment(VerticalAlignment.CENTRE);// 设置垂直对齐方式
				// wcfTitle.setBorder(Border.ALL,
				// BorderLineStyle.THIN);//设置单元格边框样式
				wcfTitle.setWrap(true);// 设置自动换行

				sheet1.setRowView(0, 800);
				sheet1.mergeCells(0, 0, 6, 0);// 合并单元格
				sheet1.addCell(new Label(0, 0, "北京市首届发明专利奖评评审结果", wcfTitle));
				// sheet1.getSettings().setFitToPages(true);
				sheet1.setColumnView(0, 8);// 设置列宽
				sheet1.addCell(new Label(0, 1, "序号", wcf));
				sheet1.setColumnView(1, 25);
				sheet1.addCell(new Label(1, 1, "专利号", wcf));
				sheet1.setColumnView(2, 25);
				sheet1.addCell(new Label(2, 1, "项目名称", wcf));
				sheet1.setColumnView(3, 18);
				sheet1.addCell(new Label(3, 1, "专利权人", wcf));
				sheet1.setColumnView(4, 40);
				sheet1.addCell(new Label(4, 1, "发明人", wcf));
				sheet1.setColumnView(5, 40);
				sheet1.addCell(new Label(5, 1, "建议奖级", wcf));
				sheet1.setColumnView(6, 10);
				sheet1.addCell(new Label(6, 1, "评选奖级", wcf));
				/**
				 * 循环输出单元格内容
				 */
				for (int i = 0; i < xmReviewResults3List.size(); i++) {
					XmReviewResults3 xmReviewResults3 = xmReviewResults3List
							.get(i);
					sheet1.addCell(new Label(0, i + 2, new Integer(i + 1)
							.toString(), wcf));
					sheet1.addCell(new Label(1, i + 2, xmReviewResults3
							.getBasicInfoModel().getZlid2(), wcf));
					sheet1.addCell(new Label(2, i + 2, xmReviewResults3
							.getBasicInfoModel().getName(), wcf));
					sheet1.addCell(new Label(3, i + 2, xmReviewResults3
							.getBasicInfoModel().getZlqr(), wcf));
					sheet1.addCell(new Label(4, i + 2, xmReviewResults3
							.getBasicInfoModel().getFmr(), wcf));
					sheet1.addCell(new Label(5, i + 2, xmReviewResults3
							.getBasicInfoModel().getXkmc()
							+ "组\n建议为" + xmReviewResults3.getJydj().getName(),
							wcf));// \n为换行符号
					sheet1.addCell(new Label(6, i + 2, xmReviewResults3
							.getPxjj().getName(), wcf));
				}
				book.write();
				os.flush();
				book.close();
				os.close();
				return exportFile;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} catch (RowsExceededException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} catch (WriteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} finally {

			}
		} else {
			return null;
		}
	}

	/**
	 * 判断一个字符串data是否在字符串列表datas中 如果在则返回true，否则返回false
	 * 
	 * @param data
	 * @param datas
	 * @return
	 */
	public boolean isExitInArray(String data, List<String> datas) {
		boolean bl = false;
		if (null == datas || datas.size() <= 0) {
			return false;
		}
		for (String i : datas) {
			if (data.equals(i)) {
				bl = true;
				break;
			}
		}
		return bl;
	}
	
	/**
	 * 判断一个整数data是否在整数列表datas中 如果在则返回true，否则返回false
	 * 
	 * @param data
	 * @param datas
	 * @return
	 */
	public boolean isExitInArray(int data, List<Integer> datas) {
		boolean bl = false;
		for (Integer i : datas) {
			if (data == i) {
				bl = true;
				break;
			}
		}
		return bl;
	}

	/**
	 * 投票结果排序
	 * 
	 * @param oldList
	 * @return
	 */
	public List<VoteModel> sortList(List<VoteModel> oldList) {
		List<VoteModel> tempList = oldList;
		VoteModel tempVM;
		for (int i = 0; i < tempList.size(); i++) {
			Double maxFenshu = new Double(tempList.get(i).getFinalPrizeCount());
			VoteModel maxVM = tempList.get(i);
			int maxId = i;
			for (int j = i + 1; j < tempList.size(); j++) {
				if (new Double(tempList.get(j).getFinalPrizeCount()) > maxFenshu) {
					maxFenshu = new Double(tempList.get(j).getFinalPrizeCount());
					maxVM = tempList.get(j);
					maxId = j;
				}
			}
			if (maxId != i) {
				tempVM = tempList.get(i);
				tempList.remove(i);
				tempList.add(i, maxVM);
				tempList.remove(maxId);
				tempList.add(maxId, tempVM);
			}
		}
		return tempList;
	}
}
